home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / graphic import.export / start code / gettingmoreinfo.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  5.7 KB  |  176 lines

  1. // Graphics Importer and Exporter Samples
  2. // This example demonstrates how to extract image information
  3. // using Graphics Importers
  4. // Originally written by Sam Bushell for QuickTime "Live" '99
  5. // WWDC 2000 Introduction to QuickTime
  6. // Note: This application uses standard output (and SIOUX on the Mac)
  7.  
  8. #include "MacShell.h"
  9. #include <SIOUX.h>
  10. #include <Console.h>
  11. #include <stdio.h>
  12.  
  13. void GetMoreInfo( void )
  14. {      
  15.     OSErr err = noErr;
  16.     Handle hOpenTypeList = NewHandle(0);
  17.     long  numTypes = 0;
  18.     FSSpec    theFSSpec;
  19.     GraphicsImportComponent importer = 0;
  20.     Str31 name;
  21.     OSType udType;
  22.     short count, i;
  23.     Handle h = NULL;
  24.     Ptr p;
  25.     char nul = 0;
  26. // Insert Variables.clp here...    
  27.  
  28.  
  29.     MatrixRecord defaultMatrix;
  30.     RGBColor defaultOpColor;
  31.     Rect defaultSourceRect;
  32.     Handle colorSyncProfile = NULL;
  33.     RgnHandle defaultClip = NULL;
  34.     long defaultGraphicsMode;
  35.     short drawsAllPixels;
  36.     
  37.     SIOUXSettings.standalone = false;
  38.        SIOUXSettings.initializeTB = false;
  39.        SIOUXSettings.setupmenus = false;
  40.        SIOUXSettings.autocloseonquit = true;
  41.        SIOUXSettings.asktosaveonclose = false;
  42.        SIOUXSetTitle( "\pGet More Info" );
  43.        
  44.     printf( "Choose an image file...\n\n" );
  45.  
  46.     BuildGraphicsImporterValidFileTypes( hOpenTypeList, &numTypes );
  47.     HLock( hOpenTypeList );
  48.     
  49.     // prompt for an image file.
  50.     err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL);
  51.     DisposeHandle( hOpenTypeList );
  52.     if (err) return;
  53.     
  54.     // locate and open a graphics importer component
  55.     err = GetGraphicsImporterForFile( &theFSSpec, &importer );
  56.  
  57.     // get the file's image description.
  58. // Step 1. Insert GetImageDescription.clp here...
  59.  
  60.     if( desc && *desc ) {
  61.         // print basic statistics from the image description.
  62.         printf( "Image width:   %d\n", (*desc)->width );
  63.         printf( "Image height:  %d\n", (*desc)->height );
  64.         printf( "Depth:         %d\n", (*desc)->depth );
  65.         BlockMoveData( (*desc)->name, name, sizeof(name) );
  66.         CopyPascalStringToC(name, (char *)name);
  67.         printf( "Format:        %s\n", name);
  68.         printf( "Resolution:    %.1f x %.1f dpi\n", Fix2X((*desc)->hRes), Fix2X((*desc)->vRes) );
  69.         
  70.         // an image description may contain a CLUT (Color Look Up Table)
  71.         if( ((*desc)->depth < 16) || ((*desc)->depth > 32) ) {
  72.             // get the CTable from the image description
  73. // Step 2. Insert CTable.clp here...
  74.  
  75.             if( colorTable ) {
  76.                 printf( "\nImage has a color table.\n" );
  77.                 DisposeCTable( colorTable );
  78.             }
  79.         }
  80.     }
  81.         
  82.     // NOTE: GraphicsImportGetNaturalBounds() is just shorthand that builds a 
  83.     // rectangle from the image description's width and height.
  84.     
  85.     // get and print out the file's metadata
  86.     
  87.     // create a new user data structure  
  88. // Step 3. Insert NewUserData.clp here...
  89.  
  90.     
  91.     // extract metadata from an image and add it to an already alocated user data structure
  92. // Step 4. Insert GetMetaData.clp here...
  93.     
  94.     h = NewHandle(0);
  95.     
  96.     //  retrieve the first user data type from the user data list
  97. // Step 5. Insert GetNextUserDataType.clp here...
  98.  
  99.     if( 0 != udType ) {
  100.         printf( "\nMeta-data:\n" );
  101.         do {            
  102.             // determine the number of items of a given type in a user data list
  103.             count = CountUserDataType( userData, udType );
  104.             for( i = 1; i <= count; i++ ) {
  105.                 // if the first letter of udType is 0xA9, the copyright symbol, 
  106.                 // then use GetUserDataText instead of GetUserData
  107.                 // there's a list of interesting user data types in <Movies.h>
  108.                 if( (udType>>24) == 0xA9 ) {
  109.                     // retrieve language-tagged text from an item
  110.                     err = GetUserDataText( userData,        // user data list
  111.                                            h,                // handle to recieve the data
  112.                                            udType,            // user item's type value
  113.                                            i,                // item's index value
  114.                                            langEnglish );    // language code of text to be retrieved    
  115.                     // nul-terminate the string in the handle.
  116.                     PtrAndHand( &nul, h, 1 );
  117.                     // turn any CRs into spaces (to work around SIOUX behavior).
  118.                     p = *h; while( *p ) { if( *p == 13 ) *p = ' '; p++; };
  119.                     HLock( h );
  120.                     printf( "  %c%c%c%c: %s\n", (char)(udType>>24), (char)(udType>>16), 
  121.                             (char)(udType>>8), (char)udType, *h );
  122.                     HUnlock( h );
  123.                 }
  124.                 else {
  125.                     // get a specified user data item
  126.                     err = GetUserData( userData,    // user data list
  127.                                        h,            // handle to recieve the data
  128.                                        udType,        // user item's type value
  129.                                        i );            // item's index value
  130.                     printf( "  %c%c%c%c: [%d bytes]\n", (char)(udType>>24), (char)(udType>>16), 
  131.                             (char)(udType>>8), (char)udType, GetHandleSize(h) );
  132.                 }
  133.             }
  134.             //  retrieve the next user data type from the user data list
  135.             udType = GetNextUserDataType( userData, udType );
  136.         } while( 0 != udType );
  137.     }
  138.     DisposeUserData( userData );
  139.     DisposeHandle( h );
  140.     printf( "\n" );
  141.     
  142.     // print out some more esoteric properties
  143. // Insert Step6.clp here...
  144.  
  145.     
  146.     // might this image have holes?  
  147.     drawsAllPixels = graphicsImporterDrawsAllPixels;
  148.     // find out if the graphics importer expects to draw every pixel
  149.     // as some image file formats permit non-rectangular images or images
  150.     // with transparent regions when such an image is drawn, not every
  151.     // pixel in the boundary rectangle will be changed
  152.     // ignore any error
  153. // Step 7. Insert DoesDrawAllPixels.clp here...
  154.  
  155.     switch( drawsAllPixels ) {
  156.         case graphicsImporterDrawsAllPixels:
  157.             printf( "Image will overwrite every pixel in its DestRect.\n" );
  158.             break;
  159.         case graphicsImporterDoesntDrawAllPixels:
  160.             printf( "Image will not overwrite every pixel in its DestRect.\n" );
  161.             break;
  162.         case graphicsImporterDontKnowIfDrawAllPixels:
  163.             printf( "Image may or may not overwrite every pixel in its DestRect.\n" );
  164.             break;
  165.     }
  166.  
  167.     // Note: In a multiple-image file, the image description, metadata, 
  168.     // default settings, etc. can be different for each image.
  169.     
  170.     CloseComponent( importer );
  171.     DisposeHandle( (Handle)desc );
  172.     if( defaultClip ) DisposeRgn( defaultClip );
  173.     DisposeHandle( colorSyncProfile );
  174.     
  175.     pause();
  176. }